﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxMenu;
using RR;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected RegistRar regrar = new RegistRar();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void grd_kontr_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        if (e.NewValues["CODE"] == null) 
            e.NewValues["CODE"] = regrar.Gen_id("KONTRAGENT_gen");
    }

    protected void menu_exp_ItemClick(object source, MenuItemEventArgs e)
    {
        if (e.Item.Name == "btn_Excel")
            grd_export.WriteXlsxToResponse();
    }
    /// <summary>
    /// динамическое условие для EntityDataSource в момент редактирования записи
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grd_kontr_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
    {
        if (e.Column.FieldName == "DIR" & e.KeyValue!=null)
        {
            var grid = e.Column.Grid;
            string kontr = grd_kontr.GetRowValues(e.VisibleIndex, "CODE").ToString();
            ds_worker.WhereParameters.Clear();
            ds_worker.AutoGenerateWhereClause = true;
            ds_worker.WhereParameters.Add("KONTRAGENT", System.Data.DbType.Int32, kontr);
        }
    }
    protected void ds_worker_Selecting(object sender, EntityDataSourceSelectingEventArgs e)
    {

    }
}